package cs551.listtracker.adapter;

/*
 * Copyright (C) 2013 Surviving with Android (http://www.survivingwithandroid.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import cs551.listtracker.R;
import cs551.listtracker.structure.ShoppingList;

public class ListofListsAdapter extends ArrayAdapter<ShoppingList> {

	private List<ShoppingList> shoppingListList;
	private Context ctx;

	public ListofListsAdapter(List<ShoppingList> shoppingListList, Context ctx) {
		super(ctx, R.layout.listrow_layout, shoppingListList);
		this.ctx = ctx;
		this.shoppingListList = shoppingListList;
	}

	@Override
	public int getCount() {
		return shoppingListList.size();
	}

	@Override
	public ShoppingList getItem(int position) {
		return shoppingListList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return shoppingListList.get(position).hashCode();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;

		if (v == null) {
			LayoutInflater inf = (LayoutInflater) ctx
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = (View) inf.inflate(R.layout.listrow_layout, null);
		}
		TextView tName = (TextView) v.findViewById(R.id.listName);
		TextView tText = (TextView) v.findViewById(R.id.listDetails);
		TextView tDate = (TextView) v.findViewById(R.id.listDate);

		
		ShoppingList list = shoppingListList.get(position);
		tName.setText(list.title);
		System.out.println(list.noChecked());
		tText.setText("[" + list.noChecked() +"/" + list.shopList_full.size() + "] " +list.costString());
		tDate.setText(list.time);
		
		return v;
	}

}
